﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;


namespace ShortcutShow
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public String a { get; set; }
        int i = 0;
        System.Windows.Threading.DispatcherTimer dt;

        public MainWindow()
        {
            InitializeComponent();
        }


        void dt_Tick(object sender, EventArgs e) //timer tick
        {
            if (i > 1) //if time spent is more than 9 seconds
                this.Visibility = System.Windows.Visibility.Hidden; //here is your instruction: for examplse this.Close() will close your mainwindow
            else     //....else....
                i++; //contor++
        }

        public void makeVisible(String a){
            label1.Content = a;
            this.Visibility = System.Windows.Visibility.Visible;
            i = 0;
        }

        public void refreshSettings()
        {
            var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
            this.Left = desktopWorkingArea.Right - this.Width;
            this.Top = desktopWorkingArea.Bottom - this.Height;

            String roh = Properties.Settings.Default.Corner;

            switch (roh)
            {
                case "DR":
                    this.Left = desktopWorkingArea.Right - this.Width;
                    this.Top = desktopWorkingArea.Bottom - this.Height;
                    break;
                case "DL":
                    this.Left = 5;
                    this.Top = desktopWorkingArea.Bottom - this.Height;
                    break;
                case "UR":
                    this.Left = desktopWorkingArea.Right - this.Width;
                    this.Top = 5;
                    break;
                case "UL":
                    this.Left = 5;
                    this.Top = 5;
                    break;
                case "CUSTOM":
                    this.Left = Properties.Settings.Default.Left;
                    this.Top = Properties.Settings.Default.Top;
                    break;
                default:
                    this.Left = desktopWorkingArea.Right - this.Width;
                    this.Top = desktopWorkingArea.Bottom - this.Height;
                    break;
            }

            this.Opacity = Properties.Settings.Default.Opacity;
            System.Drawing.Color a = Properties.Settings.Default.BackColor;
            this.Background = new SolidColorBrush(Color.FromArgb(a.A, a.R, a.G, a.B));
            System.Drawing.Color b = Properties.Settings.Default.FontColor;
            label1.Foreground = new SolidColorBrush(Color.FromArgb(b.A, b.R, b.G, b.B));
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            refreshSettings();       
            
            dt = new System.Windows.Threading.DispatcherTimer();
            dt.Interval = new TimeSpan(0, 0, 0, 0, 500); //set the interval 1 second
            dt.Start(); //start the timer
            dt.Tick += new EventHandler(dt_Tick); //set the timer tick
        }
    }
}
